package com.liu.handler;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 基于注解的全局异常处理
 */
@ControllerAdvice  //代表的时异常 增加控制类 定义全局异常处理类
public class GlobalAnnotationExceptionHandler {
    @ExceptionHandler(NullPointerException.class)
    public String handler(NullPointerException e , Model model){
        model.addAttribute("msg",e.getMessage());
        return "/error.jsp";
    }
}
